#ifndef QPCAP_H
#define QPCAP_H

#include <QtNetwork/QHostAddress>
#include <QDebug>
#include <QObject>
#include <QPcapPacket.h>
#include <QThread>
#include <QList>
#include <QString>

#define HAVE_REMOTE
#include <pcap.h>



class QPcap : public QThread {
    Q_OBJECT
public:
    explicit QPcap(int refreshIntreval = 1000, QObject * parent = 0);

    ~QPcap();

    pcap_if_t * getInterfaces();
    void run();
    void selectInterface(int selectedInterface);
    void stop();
    void openInterface();
    QList<pcap_if_t*> getInterfacesList();
    int getIndexFromInterfaceName(QString name);
    QString getNameFromInterfaceIndex(int index);


    void readPackets();

    void addingPortRestrict(int port);
    void addingProtocolRestrict(int protocol);
    void addingPortRestrictRange(int min, int max);

    bool isPortIntoRestrict(int port);
    bool isProtocolIntoRestrict(int protocol);

    QString getActiveInterfaceName();
    void setRefreshInterval(int time);

    static pcap_if_t * getAllInterfaces();

    const static int protocolICMP = 1;
    const static int protocolIGMP = 2;
    const static int protocolTCP = 6;
    const static int protocolUDP = 17;
    const static int protocolENCAP = 41;
    const static int protocolOSPF = 89;
    const static int protocolSCTP = 132;
private:
    pcap_t * handle;
    pcap_if_t * interfaces;
    int selectedInterface;
    int refreshInterval;

    QList<int*> * portsRestrict;
    QList<int> * protocolsRestrict;

    bool souldStopCapturing;

signals:
    void signalNewPacket(QPcapPacket * packet);
};




#endif // QPCAP_H
